package com.taoyibao.hongcanting.ui.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;

import java.util.List;

/**
 * @author TangAnna
 * @description: tablayout 和Viewpager一起的Adapter
 * @date :${DATA} 11:44
 */
public class MyTabFragmentAdapter extends FragmentStatePagerAdapter {
    private List<String> mTitleList;
    private List<Fragment> arrayListFragment;

    public MyTabFragmentAdapter(FragmentManager fm, List<String> titleList, List<Fragment> arrayListFragment) {
        super(fm);
        mTitleList = titleList;
        this.arrayListFragment = arrayListFragment;
    }

    public MyTabFragmentAdapter(FragmentManager fm, List<Fragment> arrayListFragment) {
        super(fm);
        this.arrayListFragment = arrayListFragment;
    }


    public MyTabFragmentAdapter(FragmentManager fm) {
        super(fm);
    }

    @Override
    public int getCount() {
        return arrayListFragment == null ? 0 : arrayListFragment.size();
    }

    @Override
    public Fragment getItem(int index) {//直接创建fragment对象并返回
        return arrayListFragment.get(index);
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return mTitleList == null ? super.getPageTitle(position) : mTitleList.get(position);
    }
}
